package com.example.demo1.controller;

import com.example.demo1.repository.PictureDao;
import com.example.demo1.service.IndividualService;
import com.example.demo1.utils.IndiExper;
import com.example.demo1.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/individual")
public class IndividualController {
    @Autowired
    public IndividualService individualService;
    @Autowired
    public PictureDao pictureDao;
    @PostMapping("/experiment")
    public Result list(String username){
      List<IndiExper> indiExpers=  individualService.list(username);
      return Result.success(indiExpers);
    }
   @PostMapping ("/look")
    public Result look(IndiExper indiExper){
       String url= pictureDao.findPictureByExperimentNameAndPictureNameAndTeamName(indiExper.getExperiment_name(),indiExper.getPicture_name(),indiExper.getTeam_name()) ;
       if (url == null) {
           throw new IllegalArgumentException("未找到与提供的实验名称和团队名称匹配的图片");
       }
       String newurl = url.substring(url.lastIndexOf('/')+1);
       return Result.success(newurl,"查询成功");
   }
    @DeleteMapping("/{id}")
    public Result delete(IndiExper indiExper){
       individualService.delete(indiExper);
       return  Result.success("成功删除");
    }

}
